CSharpTest.Net
Clone Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Collections Namespace > ReadOnlyList<T> Class : Clone Method

Glossary Item Box

Returns a shallow clone of this object

Syntax

Visual Basic (Declaration) 
Public Function Clone() As ReadOnlyList(Of T)
C# 
public ReadOnlyList<T> Clone()

Example

Library/Library.Test/TestReadOnlyList.cs

C#Copy Code
List<string> strings = new List<string>(new string[] { "a", "b", "c" });
ReadOnlyList<String> read = new ReadOnlyList<string>(strings, false);

Assert.AreEqual(3, read.Count);
strings.RemoveAt(2);
Assert.AreEqual(2, read.Count);
Assert.AreEqual("a", read[0]);
Assert.AreEqual("b", read[1]);

Assert.AreEqual("a,b", String.Join(",", read.Clone().ToArray()));
VB.NETCopy Code
Dim strings As New List(Of String)(New String() {"a", "b", "c"})
Dim read As ReadOnlyList(Of [String]) = New ReadOnlyList(Of String)(strings, False)

Assert.AreEqual(3, read.Count)
strings.RemoveAt(2)
Assert.AreEqual(2, read.Count)
Assert.AreEqual("a", read(0))
Assert.AreEqual("b", read(1))

Assert.AreEqual("a,b", [String].Join(",", read.Clone().ToArray()))

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys